package com.jprocms.module.cms.controller.portal.api;

import com.jpro.framework.common.pojo.CommonResult;
import com.jpro.framework.common.util.object.BeanUtils;
import com.jprocms.module.cms.controller.admin.sysword.vo.SysWordRespVO;
import com.jprocms.module.cms.dal.dataobject.sysword.SysWordDO;
import com.jprocms.module.cms.service.sysword.SysWordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static com.jpro.framework.common.pojo.CommonResult.success;
import static com.jprocms.module.cms.constant.CmsSysConstants.FRONT_API;


@Tag(name = "词汇")
@RestController
@RequestMapping(FRONT_API + "/sys-word")
@Validated
public class SysWordApiController {

    @Resource
    private SysWordService sysWordService;

    @GetMapping("/getSearchSuggest")
    @Operation(summary = "获得推荐词包含搜索词的推荐词")
    public CommonResult<List<SysWordRespVO>> getSearchSuggest(@RequestParam("text") String text) {
        final List<SysWordDO> easyErrorWords = sysWordService.findSearchSuggest(text);
        return success(BeanUtils.toBean(easyErrorWords, SysWordRespVO.class));
    }


}
